package com.xujiang.myblog.tools;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.xujiang.myblog.util.L;

import net.danlew.android.joda.JodaTimeAndroid;

import java.io.File;

/**
 * Created by xujiang on 2017/4/14.
 */

public class Common {

    private static String PROJECT_NAME = "com.xujiang.myblog";
    private static boolean DEBUG;
    private static File mExternalCacheDir;

    public static void init(@NonNull Context context, String projectName, boolean isDebug) {
        if (TextUtils.isEmpty(projectName)) {
            PROJECT_NAME = context.getPackageName();
        } else {
            PROJECT_NAME = projectName;
        }
        //是否debug
        DEBUG = isDebug;
        mExternalCacheDir = FileUtils.getSDExternalPath(context);
        //joda-time-android是一个专门用于在Android平台处理时间/日期的类库，无论您是计算日期、打印日期，或是解析日期，joda-time-android都提供了很便捷的方法。
        JodaTimeAndroid.init(context);
        //日志打印的初始化
        L.init(PROJECT_NAME,isDebug);
    }

    public static String getProjectName() {
        if (TextUtils.isEmpty(PROJECT_NAME)) {
            throw new IllegalStateException("not init Common");
        }
        return PROJECT_NAME;
    }

    public static boolean isDebug() {
        return DEBUG;
    }


    //获得sd卡目录
    public static File getSDExternalPath() {
        if (mExternalCacheDir == null) {
            throw new IllegalStateException("not init Common");
        }
        return mExternalCacheDir;
    }
}
